/******************************************************************************
 * SVN­Version­Information:
 * ­­­­­­­­­­­­­­­­­­­­­­­­---------------------
 * $LastChangedRevision: 135 $
 * $LastChangedBy: MV $
 * $LastChangedDate: 2009-06-26 21:00:39 +0200 (Fri, 26 Jun 2009) $
 * $HeadURL: svn://lvis10.fbm.fht-stuttgart.de/common/Common/src/de/hft_stuttgart/botwar/common/commands/ChatCmd.java $
 ******************************************************************************/
package de.hft_stuttgart.botwar.common.commands;

import de.hft_stuttgart.botwar.common.interfaces.IRemotePlayer;

/**
 * This command represents a Chatmessage.
 * @author sdegiorgi@gmail.com
 */
public final class ChatCmd extends Cmd {

    private final IRemotePlayer.CHATTYPE chattype;
    private final String chatsender;
    private final String chatmessage;

    /**
     * @param type the type of which the chat message is
     * @param sender the origin of the chat message (that is: player)
     * @param msg the message that was sent
     */
    public ChatCmd(final IRemotePlayer.CHATTYPE type, final String sender,
            final String msg) {
        this.chattype = type;
        this.chatsender = sender;
        this.chatmessage = msg;
    }

    /**
     * @return CHATTYPE of message
     */
    public IRemotePlayer.CHATTYPE getChatType() {
        return this.chattype;
    }

    /**
     * @return chatsender of message
     */
    public String getChatSender() {
        return this.chatsender;
    }

    /**
     * @return CHATMESSAGE, the content
     */
    public String getChatMessage() {
        return this.chatmessage;
    }

    /**
     * Overrides method equals.
     * @param obj object to compare
     * @return boolean true or false
     */
    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ChatCmd other = (ChatCmd) obj;
        if ((this.chattype != other.chattype) ||
                !this.chatsender.equals(other.chatsender) ||
                !this.chatmessage.equals(other.chatmessage)) {
            return false;
        }
        return true;
    }

    /**
     * Method to get a String representation of the object
     * @return String stating the Object
     */
    @Override
    public String toString() {
        return String.format("%s sends message '%s' in mode %s",
                getChatSender(), getChatMessage(), getChatType());

    }
}

